package com.github.lee.unsplash.model.repository

import com.github.lee.core.room.DataStorePreferences
import com.github.lee.unsplash.model.api.AuthApi
import javax.inject.Inject

private const val KEY_ACCOUNT = "KEY_ACCOUNT"

class AuthRepository @Inject constructor(
    private val api: AuthApi,
    private val local: DataStorePreferences
) {

    suspend fun oauth(
        clientId: String,
        clientSecret: String,
        code: String
    ) = api.oauth(clientId, clientSecret, code)

    suspend fun isLogin() =
        accountToken().isNullOrEmpty()

    suspend fun accountToken() =
        local.getString(KEY_ACCOUNT, "")


}